package org.linlinjava.litemall.wx.web;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.linlinjava.litemall.core.util.ResponseUtil;
import org.linlinjava.litemall.core.validator.Sort;
import org.linlinjava.litemall.db.domain.PiccPatientMeasure;
import org.linlinjava.litemall.db.service.PiccMeasureService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("wx/measure")
@Validated
public class WxPiccMeasureController {
    private final Log logger = LogFactory.getLog(WxPiccMeasureController.class);
    @Autowired
    PiccMeasureService piccMeasureService;

    @PostMapping("create")
    public Object addMeasure(@RequestBody PiccPatientMeasure measure){
        PiccPatientMeasure record = piccMeasureService.add(measure);
        return ResponseUtil.ok(record);
    }

    @GetMapping("list")
    public Object getListByPatientId(@RequestParam Integer patientId,
                                    @RequestParam(defaultValue = "1") Integer page,
                                    @RequestParam(defaultValue = "10") Integer limit,
                                    @Sort @RequestParam(defaultValue = "add_time") String sort,
                                    @RequestParam(defaultValue = "desc") String order){
        return piccMeasureService.getListByPatientid(patientId, page, limit,
                sort, order);
    }

    @GetMapping("all")
    public Object getAll(@RequestParam(defaultValue = "0") Integer nurseId,
                         @RequestParam(defaultValue = "1") Integer page,
                         @RequestParam(defaultValue = "10") Integer limit,
                         @Sort @RequestParam(defaultValue = "add_time") String sort,
                         @RequestParam(defaultValue = "desc") String order) {
        logger.debug("LJF--->measure get ALL");
        List<PiccPatientMeasure> mList = piccMeasureService.getAllList(nurseId, page, limit,
                sort, order);
        logger.debug(mList);
        return ResponseUtil.ok(mList);
    }
}
